Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix crash on invalid portable or Steam folder #2506

Merged
merged 2 commits into from
Aug 22, 2018

Conversation

HebaruSan
Copy link
Member

@HebaruSan HebaruSan commented Aug 19, 2018

Background

A game folder needs a few things to be considered valid by CKAN:

  • GameData folder
  • Version info, from readme.txt, buildID64.txt, or buildid.txt

Without these, CKAN can't do its job, so it looks for other game folders or gives up and asks the user to specify one. (Or at least that's how it's supposed to work.)

Problem

If you have KSP installed in your Steam library, and you delete the readme.txt, buildID64.txt, and buildid.txt files, GUI should show the Select KSP Install window to let you specify a valid game folder, but instead it throws this exception:

CKAN.NotKSPDirKraken: Could not find KSP version in buildID.txt or readme.txt
at CKAN.KSP.CkanDir()
at CKAN.Main..ctor(String[] cmdlineArgs, KSPManager mgr, GUIUser user, Boolean showConsole)
at CKAN.GUI.Main_(String[] args, KSPManager manager, Boolean showConsole)
at CKAN.CmdLine.MainClass.Main(String[] args)

Similarly, the same problem can happen if you run ckan.exe from a folder that also has a GameData subfolder but not a full copy of KSP.

Cause

That exception means we've loaded and tried to use an invalid game folder; we should be skipping it instead. We check whether a game folder is valid earlier if it's loaded from the registry, but not if it's being auto-added because KSP.FindGameDir found it in a Steam library. In effect the Steam library logic skips some of the folder validation.

Similarly, the "portable" instance logic also skips the same validation.

Changes

Now FindAndRegisterDefaultInstance won't add or return invalid instances, and an invalid "portable" instance will be skipped.
This should mean that GUI will pop up the Select KSP Install window, as intended.

Fixes #2504.

@HebaruSan HebaruSan added Bug GUI Issues affecting the interactive GUI Core (ckan.dll) Issues affecting the core part of CKAN Pull request labels Aug 19, 2018
@Drakkith
Copy link

Thanks HebaruSan. I will try this version as soon as I get back home to my desktop tomorrow.

@Drakkith
Copy link

Hmmm. Still getting an exception:

Unhandled exception:
CKAN.NotKSPDirKraken: Could not find KSP version in buildID.txt or readme.txt
at CKAN.KSP.CkanDir()
at CKAN.Main..ctor(String[] cmdlineArgs, KSPManager mgr, GUIUser user, Boolean showConsole)
at CKAN.GUI.Main_(String[] args, KSPManager manager, Boolean showConsole)
at CKAN.CmdLine.MainClass.Gui(KSPManager manager, GuiOptions options, String[] args)
at CKAN.CmdLine.MainClass.RunSimpleAction(Options cmdline, CommonOptions options, String[] args, IUser user, KSPManager manager)
at CKAN.CmdLine.MainClass.Execute(KSPManager manager, CommonOptions opts, String[] args)
at CKAN.CmdLine.MainClass.Main(String[] args)

@HebaruSan
Copy link
Member Author

Thanks for trying that out! I have a new guess based on your feedback. Is there a GameData subfolder in the folder from which you're running ckan.exe? I usually run ckan from my Downloads folder, and I can reproduce this exception if I simply run mkdir GameData in that folder. There's some old logic that tries to detect if you've copied CKAN into your KSP folder that could get tripped up in such a case. I'll add a fix to this pull request...

@HebaruSan
Copy link
Member Author

HebaruSan commented Aug 20, 2018

@Drakkith, a new test component if you're available to try it while I rewrite the fix info:

@HebaruSan HebaruSan changed the title Fix crash on invalid Steam folder Fix crash on invalid portable or Steam folder Aug 20, 2018
@Drakkith
Copy link

Actually there was an empty GameData folder in my downloads folder. Must have been from unzipping a mod and then cutting the contents out. And it looks like that was the cause of my issue. I deleted the empty gamedata folder and CKAN opened right up!

@politas politas merged commit d26cf1f into KSP-CKAN:master Aug 22, 2018
@HebaruSan HebaruSan deleted the fix/crash-on-invalid-steam-folder branch August 22, 2018 14:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Core (ckan.dll) Issues affecting the core part of CKAN GUI Issues affecting the interactive GUI Pull request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants